package com.wang.springbootinit.controller.student;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.vo.AnswerRecordVO;
import com.wang.springbootinit.service.AnswerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/student/question/record")
public class StudentQuestionRecordController {

    @Autowired
    private AnswerRecordService answerRecordService;


    /**
     * 做题训练列表-根据章节ID查询题目列表（分页）
     * @param chapterId 章节ID
     * @param questionType 题目类型（选填）
     * @param questionCategory 题目分类（选填）
     * @param current 当前页码
     * @param pageSize 每页数量
     */
    @GetMapping("/page")
    public BaseResponse<Page<AnswerRecordVO>> getStudentQuestionPage(
            @RequestParam(required = false) Long chapterId,
            @RequestParam(required = false) Integer questionType,
            @RequestParam(required = false) Integer questionCategory,
            @RequestParam(defaultValue = "1") long current,
            @RequestParam(defaultValue = "10") long pageSize,
            HttpServletRequest request) {
        return ResultUtils.success(answerRecordService.getStudentQuestionPage(chapterId, questionType, questionCategory, current, pageSize,request));
    }


    /**
     * 做题训练列表-根据章节ID查询题目列表（分页）
     * @param chapterId 章节ID
     * @param questionType 题目类型（选填）
     * @param questionCategory 题目分类（选填）
     * @param current 当前页码
     * @param pageSize 每页数量
     */
    @GetMapping("/error/page")
    public BaseResponse<Page<AnswerRecordVO>> getStudentErrorQuestionPage(
            @RequestParam(required = false) Long chapterId,
            @RequestParam(required = false) Integer questionType,
            @RequestParam(required = false) Integer questionCategory,
            @RequestParam(defaultValue = "1") long current,
            @RequestParam(defaultValue = "10") long pageSize,
            HttpServletRequest request) {
        return ResultUtils.success(answerRecordService.getStudentErrorQuestionPage(chapterId, questionType, questionCategory, current, pageSize,request));
    }


    /**
     * 删除答题记录
     * @param id 答题记录ID
     * @return 删除结果
     */
    @PostMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteAnswerRecord(@PathVariable("id") Long id, HttpServletRequest request) {
        return ResultUtils.success(answerRecordService.deleteAnswerRecord(id, request));
    }
}
